{extend name="common:base" /}

{block name="title"}储存策略 - {$config.site_name}{/block}

{block name="main"}
<div class="mdui-container mdui-p-b-5">
  <main>
    <div class="strategy-container">
      <div class="mdui-typo">
        <blockquote class="mdui-m-l-0">
          <p>储存策略，可配置多个，使用不同的角色组来控制用户图片储存策略。</p>
        </blockquote>
      </div>
      <div id="tab" class="mdui-tab mdui-tab-scrollable" mdui-tab>
        {foreach $strategy as $key => $value}
        <a href="#tab-{$key}" class="mdui-ripple {if $key eq $config.storage_strategy}mdui-tab-active{/if}">{$value.name}</a>
        {/foreach}
      </div>
      <div class="mdui-col-sm-8 mdui-col-md-8">
        {foreach $configs as $key => $value}
        <div id="tab-{$key}" class="{if $key neq $config.storage_strategy}none{/if}">
          <form action="{:url('admin/strategy/index')}" method="post">
            {foreach $value as $val}
            <div class="mdui-textfield">
              <label class="mdui-textfield-label">{$val.title}{$val.tip ? '(' . $val.tip . ')' : ''}</label>
              {switch $val.type}
              {case text}
              <input class="mdui-textfield-input" type="{$val.input_type}" name="{$val.name}" value="{$val.value}" autocomplete="off" placeholder="{$val.title}"/>
              {/case}
              {case bool}
              <label class="mdui-switch">
                <input type="{$val.input_type}" data-name="{$val.name}" value="1" {if 1 eq $val.value}checked{/if}/>
                <i class="mdui-switch-icon"></i>
              </label>
              {/case}
              {case select}
              <select name="{$val.name}" class="mdui-select">
                {foreach $val.extend as $k => $v}
                <option value="{$k}" {if $k eq $val.value}selected{/if}>{$v}</option>
                {/foreach}
              </select>
              {/case}
              {/switch}
            </div>
            {/foreach}
            <input type="hidden" name="storage_strategy" value="{$key}">
            <button type="submit" class="mdui-btn mdui-btn-raised mdui-ripple mdui-color-theme-accent">保存</button>
            <button type="reset" class="mdui-btn mdui-btn-raised mdui-ripple">重置</button>
          </form>
        </div>
        {/foreach}
      </div>
    </div>
  </main>
</div>
{/block}
{block name="js"}
<script>
  $(function () {
    $('form').submit(function (e) {
      e.preventDefault();
      var data = $(this).serialize();
      $(this).find("input[type='checkbox']").each(function (key, value) {
        data += ("&" + $(value).data('name') + "=") + (value.checked ? value.value : 0);
      });
      app.request(this.action, data);
    })
  });
</script>
{/block}
